
//affiche simplement le parametre passe a la fonction
void print(char* string){
	printf("%s\n", string);
}


int* getDiffLines(char* string, int* count){
	*count = 0;
    int size = str_len(string);
    int i = 0;

    int* tabLines = (int*)calloc(8, sizeof(int));

    int j = 0;
	int index = 0;
    while(i<size){
        if(string[i] != 'c' && string[i] != 'a' && string[i] != ','){
            tabLines[index] += atoi(&string[i]);
            j++;
        }else{
			index++;
		}
        i++;
    }
	*count = index+1;
    return tabLines;
}

char getDiffType(char* string){
    int size = str_len(string);
    int i = 0;
    while(i<size){
        if(string[i] == 'c' || string[i] == 'a'){
            return string[i];
        }
        i++;
    }
}

void printDiff(char** errors, int count, char** file1Content, char** file2Content){
    int i = 0;
    while( i < count ){
		char c = getDiffType(errors[i]);
		int size = str_len(errors[i]);
		printf("%s\n", errors[i]);
		if(c=='c'){
		  int count;
		  int* tabLines = (int*)getDiffLines(errors[i], &count);
		  int j = tabLines[0];
		  if(count==2){
				printf("< %s", file1Content[tabLines[0]-1]);
				printf("---\n");
				printf("> %s", file2Content[tabLines[1]-1]);
		  }else{
			for(j;j<tabLines[1];j++){
				printf("< %s", file1Content[j-1]);
			}
			printf("---\n");
			j = tabLines[2];
			for(j;j<tabLines[3];j++){
				printf("> %s", file2Content[j-1]);
			}
		  }

		  free(tabLines);
		}
		i++;
    }
}


